package com.example.gateway;

/**
 * @author karidyang
 */
public class SignException extends Exception {
    private static final int MAX_SEARCH_DEPTH = 10;

    public static final String BLOCK_EXCEPTION_FLAG = "SignException";
    public SignException(String message) {
        super(message);
    }

    public static boolean isSignException(Throwable t) {
        if (null == t) {
            return false;
        }

        int counter = 0;
        Throwable cause = t;
        while (cause != null && counter++ < MAX_SEARCH_DEPTH) {
            if (cause instanceof SignException) {
                return true;
            }
            if (cause.getMessage() != null && cause.getMessage().startsWith(BLOCK_EXCEPTION_FLAG)) {
                return true;
            }
            cause = cause.getCause();
        }

        return false;
    }
}
